<?php
// +----------------------------------------------------------------------
// | ZZYY  [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2023 https://www.fastadmin.net All rights reserved.
// +----------------------------------------------------------------------
// | Author: 乘风
// +----------------------------------------------------------------------

namespace app\admin\model\zzyy;

use think\Model;


class ZzyyReserve extends Model
{

    const PAY_WAY_CARD = 1;
    const PAY_WAY_BALANCE = 2;
    const PAY_WAY_DIRECT = 3;
    const PAY_WAY_OTHER = 4;

    const STATUS_CREATED = 0;
    const STATUS_SUCCESS = 1;
    const STATUS_CANCELLED = 2;


    // 表名
    protected $name = 'zzyy_reserve';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
    ];
    

    
    public function getPayWayList()
    {
        return ['1' => __('Pay_way 1'), '2' => __('Pay_way 2'), '3' => __('Pay_way 3'), '4' => __('Pay_way 4')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
    }


    public function getPayWayTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_way']) ? $data['pay_way'] : '');
        $list = $this->getPayWayList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function store()
    {
        return $this->belongsTo('ZzyyStore', 'store_id', 'id', [])->setEagerlyType(0);
    }


    public function room()
    {
        return $this->belongsTo('ZzyyRoom', 'room_id', 'id', [])->setEagerlyType(0);
    }

    public function user()
    {
        return $this->belongsTo('\\app\\admin\\model\\User', 'user_id', 'id')->setEagerlyType(0);
    }

    public function paytransaction()
    {
        return $this->belongsTo('ZzyyTransaction', 'transaction_id', 'id')->setEagerlyType(0);
    }



}